package com.ufo.store.management.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;

import com.ufo.store.management.ui.fragment.Isszmbalv3MemberListFragment;

import java.util.List;

/**
 * Created by taoli on 2017/12/28.
 */

public class Isszmbalv3MemberViewPagerAdapter extends FragmentPagerAdapter {
    private FragmentManager mFragmentManager;
    private List<String> listPoint;
    private Isszmbalv3MemberListFragment.Isszmbalv3MemberListGetProcessListener listener;
    private int ListStyle;
    private int SearchSortMode;

    public Isszmbalv3MemberViewPagerAdapter(FragmentManager fragmentManager) {
        super(fragmentManager);
        mFragmentManager = fragmentManager;
    }

    @Override
    public int getCount() {
        return listPoint.size();
    }

    @Override
    public Fragment getItem(int position) {
        Isszmbalv3MemberListFragment fragment = new Isszmbalv3MemberListFragment();
        fragment.setPosition(position);
        fragment.setIsszmbalv3MemberPointList(listPoint);
        fragment.setIsszmbalv3MemberListStyle(ListStyle);
        fragment.setIsszmbalv3MemberListGetProcessListener(listener);
        return fragment;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return "";
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        return super.instantiateItem(container, position);
    }

    public void setStyle(int s){
        ListStyle = s;
        List<Fragment> isszmbalv3MemberFragments = mFragmentManager.getFragments();
        if (isszmbalv3MemberFragments != null && isszmbalv3MemberFragments.size() != 0) {
            for (int i = 0; i < isszmbalv3MemberFragments.size(); i++) {
                Isszmbalv3MemberListFragment isszmbalv3MemberFragment = (Isszmbalv3MemberListFragment) isszmbalv3MemberFragments.get(i);
                if (isszmbalv3MemberFragment != null  && isszmbalv3MemberFragment.getUserVisibleHint()) {
                    isszmbalv3MemberFragment.setStyle(s);
                }
            }
        }
    }

    public void setTitleIsHided(boolean is){
        List<Fragment> isszmbalv3MemberFragments = mFragmentManager.getFragments();
        if (isszmbalv3MemberFragments != null && isszmbalv3MemberFragments.size() != 0) {
            for (int i = 0; i < isszmbalv3MemberFragments.size(); i++) {
                Isszmbalv3MemberListFragment isszmbalv3MemberFragment = (Isszmbalv3MemberListFragment) isszmbalv3MemberFragments.get(i);
                if (isszmbalv3MemberFragment != null && isszmbalv3MemberFragment.getUserVisibleHint()) {
                    isszmbalv3MemberFragment.setTitleIsHided(is);
                }
            }
        }
    }

    public void setSearchSortMode(int m){
        SearchSortMode = m;
        List<Fragment> isszmbalv3MemberFragments = mFragmentManager.getFragments();
        if (isszmbalv3MemberFragments != null && isszmbalv3MemberFragments.size() != 0) {
            for (int i = 0; i < isszmbalv3MemberFragments.size(); i++) {
                Isszmbalv3MemberListFragment isszmbalv3MemberFragment = (Isszmbalv3MemberListFragment) isszmbalv3MemberFragments.get(i);
                if (isszmbalv3MemberFragment != null && isszmbalv3MemberFragment.getUserVisibleHint()) {
                    isszmbalv3MemberFragment.setMemberSearchSortMode(m);
                }
            }
        }
    }

    public void setIsszmbalv3MemberListStyle(int s){
        ListStyle = s;
    }

    public void setIsszmbalv3MemberPointList(List<String> list) {
        this.listPoint = list;
    }

    public void setIsszmbalv3MemberListGetProcessListener(Isszmbalv3MemberListFragment.Isszmbalv3MemberListGetProcessListener lis) {
        this.listener = lis;
    }

    public boolean isFragmentVisible(int position) {
        boolean isV = false;
        List<Fragment> isszmbalv3MemberFragments = mFragmentManager.getFragments();
        if (isszmbalv3MemberFragments != null && isszmbalv3MemberFragments.size() != 0) {
            for (int i = 0; i < isszmbalv3MemberFragments.size(); i++) {
                Isszmbalv3MemberListFragment isszmbalv3MemberFragment = (Isszmbalv3MemberListFragment) isszmbalv3MemberFragments.get(i);
                if (isszmbalv3MemberFragment != null && isszmbalv3MemberFragment.getUserVisibleHint()) {
                    if (i == position)
                        isV = true;
                }
            }
        }
        return isV;
    }
}


